/*
    Copyright © 2010  Ahti Legonkov
    
    This file is part of j+-.
    
    j+- is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    j+- is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package cx.ath.skyflyer.javapm.util;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Ahti Legonkov
 */
public class MessageCollection {

    private final List<Message> messages = new LinkedList<Message>();

    public void add(Message.Level severity, String message, String file, int line, int column)
    {
        Message msg = new Message(severity, message, file, line, column);
        messages.add(msg);
    }

    /**
     * Adds all messages from another collection to this collection.
     * @param messageCollection
     */
    public void add(MessageCollection messageCollection) {
        for (Message msg : messageCollection.messages) {
            messages.add(msg);
        }
    }

    public void addError(String message, String file, int line, int column)
    {
        add(Message.Level.Error, message, file, line, column);
    }

    public void addWarning1(String message, String file, int line, int column)
    {
        add(Message.Level.Warning1, message, file, line, column);
    }

    public void addWarning2(String message, String file, int line, int column)
    {
        add(Message.Level.Warning2, message, file, line, column);
    }

    public void addWarning3(String message, String file, int line, int column)
    {
        add(Message.Level.Warning3, message, file, line, column);
    }

    public void addWarning4(String message, String file, int line, int column)
    {
        add(Message.Level.Warning4, message, file, line, column);
    }

    public boolean hasErrors() {
        for (Message msg : messages) {
            if (msg.Severity == Message.Level.Error)
                return true;
        }

        return false;
    }

    public boolean hasWarnings() {
        for (Message msg : messages) {
            if (msg.Severity != Message.Level.Error)
                return true;
        }

        return false;
    }

    public List<Message> getMessages() {
        return messages;
    }
}
